G = g++ -std=c++17

LIBSDIR = ./lib

LIBS = -lJNode -lJParser -lMyTextFileReaderAndWriterInterface -lTrie

.DEFAULT_GOAL: mysh
.PHONY: clean add push pull commit

mysh: main.o MyShell.o ResourceManager.o MyShellGlobalVariables.o MyShellAssistFunctions.o InternalCommands.o Executor.o MyShellWord.o MyShellLexicalAnalyzer.o MyShellGrammarNode.o MyShellException.o MyShellParser.o MyShellActionScope.o
	$(G) -pthread -o mysh main.o MyShell.o ResourceManager.o MyShellGlobalVariables.o MyShellAssistFunctions.o InternalCommands.o Executor.o MyShellWord.o MyShellLexicalAnalyzer.o MyShellGrammarNode.o MyShellException.o MyShellParser.o MyShellActionScope.o -L$(LIBSDIR) $(LIBS)

main.o: main.cpp MyShell.h MyShellNamespace.h ResourceManager.h
	$(G) -c main.cpp

MyShell.o: MyShell.cpp MyShell.h MyShellNamespace.h ResourceManager.h \
 Trie.h JParserNamespace.h JNode.h JParser.h \
 MyShellGlobalVariables.h MyShellAssistFunctions.h Executor.h \
 InternalCommands.h MyTextFileReaderAndWriterInterface.h
	$(G) -c MyShell.cpp

ResourceManager.o: ResourceManager.cpp ResourceManager.h MyShellNamespace.h Trie.h
	$(G) -c ResourceManager.cpp

MyShellGlobalVariables.o: MyShellGlobalVariables.cpp MyShellGlobalVariables.h MyShellNamespace.h ResourceManager.h Trie.h JParserNamespace.h JNode.h
	$(G) -c MyShellGlobalVariables.cpp

MyShellAssistFunctions.o: MyShellAssistFunctions.cpp MyShellAssistFunctions.h MyShellNamespace.h MyShellGlobalVariables.h ResourceManager.h Trie.h JParserNamespace.h JNode.h
	$(G) -c MyShellAssistFunctions.cpp

InternalCommands.o: InternalCommands.cpp InternalCommands.h MyShellNamespace.h MyShellGlobalVariables.h ResourceManager.h Trie.h JParserNamespace.h MyShellAssistFunctions.h MyTextFileReaderAndWriterInterface.h JParser.h JNode.h MyShellLexicalAnalyzer.h MyShellWord.h MyShellParser.h MyShellGrammarNode.h MyShellException.h Executor.h
	$(G) -c InternalCommands.cpp

Executor.o: Executor.cpp Executor.h MyShellNamespace.h InternalCommands.h MyShellGlobalVariables.h ResourceManager.h Trie.h JParserNamespace.h JNode.h MyShellAssistFunctions.h MyShellParser.h MyShellActionScope.h MyShellException.h
	$(G) -pthread -c Executor.cpp

MyShellWord.o: MyShellWord.cpp MyShellWord.h MyShellNamespace.h
	$(G) -c MyShellWord.cpp

MyShellLexicalAnalyzer.o: MyShellLexicalAnalyzer.cpp MyShellLexicalAnalyzer.h MyShellNamespace.h MyShellWord.h MyShellGlobalVariables.h ResourceManager.h Trie.h JParserNamespace.h JNode.h
	$(G) -c MyShellLexicalAnalyzer.cpp

MyShellException.o: MyShellException.cpp MyShellException.h MyShellNamespace.h
	$(G) -c MyShellException.cpp

MyShellGrammarNode.o: MyShellGrammarNode.cpp MyShellGrammarNode.h MyShellNamespace.h MyShellWord.h
	$(G) -c MyShellGrammarNode.cpp

MyShellParser.o: MyShellParser.cpp MyShellParser.h MyShellNamespace.h MyShellGrammarNode.h MyShellWord.h MyShellException.h
	$(G) -c MyShellParser.cpp

MyShellActionScope.o: MyShellActionScope.cpp MyShellActionScope.h MyShellNamespace.h MyShellWord.h MyShellException.h MyShellGrammarNode.h
	$(G) -c MyShellActionScope.cpp

# JNode.o: JNode.cpp JNode.h JParserNamespace.h
# 	  $(G) -c JNode.cpp
#     ar rcs libJNode.a JNode.o

# JParser.o: JParser.cpp JParser.h JParserNamespace.h JNode.h JParserNamespace.h
#  	  $(G) -c JParser.cpp
#     ar rcs libJParser.a JParser.o

# Trie.o: Trie.cpp Trie.h
#	  $(G) -c Trie.cpp
#     ar rcs libTrie.a Trie.o

# MyTextFileReaderAndWriterInterface.o: MyTextFileReaderAndWriterInterface.cpp MyTextFileReaderAndWriterInterface.h
# 	$(G) -c MyTextFileReaderAndWriterInterface.cpp
#     ar rcs libMyTextFileReaderAndWriterInterface.a MyTextFileReaderAndWriterInterface.o

clean:
	-rm *.o
	-rm mysh

add:
	-git add ./*.h
	-git add ./*.cpp
	-git add ./*.txt
	-git add ./makefile
	-git add ./.myshrc
	-git add ./.mysh_history
	-git add ./bin/*
	-git add ./external_commands_code/*
	-git add ./lib/*
	-git add ./doc/*
	-git add ./scripts/*.mysh
	-git add ./*.mysh

commit:
	-git commit -a -m "makefile default commit"

push:
	-git push

pull:
	-git pull
